const jwt = require("jwt-simple");


const  jwtEncode =(adminName,secret)=>{
    return jwt.encode({
        adminName,
        exp: Date.now() / 1000 + 60 * 60 * 24 * 7
    }, secret)
}


const jwtDecode =(token,secret)=>{
    try{
        const {
            adminName
        }=jwt.decode(token,secret+'');
        
        //如果解码成功，返回一个对象 code状态为1
        return {
            code:1,
            adminName

        }
    }catch(e){
        //如果解码失败 则返回一个对象，状态为0
        console.log(e.message);
        return{
            code:0
        }
    }
}
module.exports={
    jwtEncode,
    jwtDecode
}

